<template>
	<div :class="['table-list-container', { 'close-width': isClosedRef }]">
		<!-- <BaseLoading v-if="isLoadingRef" /> -->

		<a-table bordered :data-source="props.rewardPunishmentList" :columns="columns(userInfo?.identity)" 
			:rowKey="(record) => record?.RewardPunishmentId"
            :row-selection="{ selectedRowKeys: idsRef, onChange: onSelectChange }" 
		:pagination="false" :scroll="{ x: true }" :loading="isLoadingRef">
			<template #bodyCell="{ column, text, record }">
				<!-- 员工姓名 -->
				<template v-if="column.dataIndex === 'staffInfo' &&
					column.key === 'staffName'
					">
					{{ text?.staffName }}
				</template>
				<!-- 部门 -->
				<template v-if="column.dataIndex === 'staffInfo' &&
					column.key === 'departmentName'
					">
					{{ text?.departmentInfo?.departmentName }}
				</template>
				<!-- 奖惩类型 -->
				<template v-if="column.dataIndex === 'rewardPunishmentType'
					">
					<a-tag v-if="text == 1" color="orange">
						{{ map.rewardPunishment.get(text) }}
					</a-tag>
					<a-tag v-if="text == 2" color="red">
						{{ map.rewardPunishment.get(text) }}
					</a-tag>
					<a-tag v-if="text == 3 || text == 4" color="green">
						{{ map.rewardPunishment.get(text) }}
					</a-tag>
				</template>
				<!-- 调整薪资 -->
				<template v-if="column.dataIndex === 'newSalary'
					">
					{{ text }}
				</template>
				<!-- 调薪原因 -->
				<template v-if="column.dataIndex === 'adjustReason'
					">
					{{ text }}
				</template>
				<!-- 考核时间 -->
				<template v-if="column.dataIndex === 'date'">
					{{ formatDate(text) }}
				</template>
			</template>
		</a-table>
	</div>
</template>

<script setup lang="ts">
import { getCurrentInstance, onBeforeMount, Ref, toRefs, UnwrapRef } from "vue";
import { computed, defineComponent, reactive, ref } from "vue";
import { cloneDeep } from "lodash-es";
import { storeToRefs } from "pinia";
import appStore from "@/store";
import columns from "../colums";
import { formatYear, formatDate, formatBirthday } from "@/utils/format";
import map from '@/utils/map.js';

interface DataItem {
	staffInfo: object;
	salaryType: number;
	adjustmentReason: string;
	newSalary: string;
	date: string;
}
interface PropTypes {
	rewardPunishmentList: DataItem[];
}
const props = defineProps<PropTypes>();
const userInfo = JSON.parse(sessionStorage.getItem("userInfo") || "");
const { isClosedRef, isLoadingRef } = storeToRefs(appStore.useRewardPunishmentStore);
// type Key = string | number;
// const state = reactive<{
// 	selectedRowKeys: Key[];
// 	loading: boolean;
// }>({
// 	selectedRowKeys: [], // Check here to configure the default column
// 	loading: false,
// });
// const hasSelected = computed(() => state.selectedRowKeys.length > 0);
// const start = () => {
// 	state.loading = true;
// 	// ajax request after empty completing
// 	setTimeout(() => {
// 		state.loading = false;
// 		state.selectedRowKeys = [];
// 	}, 1000);
// };
// const onSelectChange = (selectedRowKeys: Key[]) => {
// 	console.log("selectedRowKeys changed: ", selectedRowKeys);
// 	state.selectedRowKeys = selectedRowKeys;
// };

// 选择删除
const { idsRef } = storeToRefs(appStore.useCommonStore);
const onSelectChange = (keys) => {
    const arr:any =[
        ...idsRef.value,
        ...keys,
    ];
    idsRef.value = arr;
};

</script>

<style lang="less">
.table-list-container {
	width: calc(100% - 260px);
	margin-top: 1px;
	margin-left: 1px;

	&.close-width {
		width: 100%;
	}
}

.ant-table-row {
	height: 60px;
	box-sizing: border-box;
	// background-color: #108ee9;
}

.ant-table-cell {
	height: 60px;
	box-sizing: border-box;
}

.editable-cell {
	position: relative;

	.editable-cell-input-wrapper,
	.editable-cell-text-wrapper {
		padding-right: 24px;
	}

	.editable-cell-text-wrapper {
		padding: 5px 24px 10px 14px;
		// background-color: #f40;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.editable-cell-icon-edit,
	.editable-cell-icon-save {
		position: absolute;
		right: 0;
		width: 30px;
		height: 30px;
		line-height: 30px;
		cursor: pointer;
		margin-right: 2px;

		span {
			width: 40px;
			height: 30px;
		}
	}

	.editable-cell-icon-edit {
		margin-top: 4px;
		// display: none;
	}

	.editable-cell-icon-save {
		line-height: 30px;
	}

	.editable-cell-icon-edit:hover,
	.editable-cell-icon-save:hover {
		color: #108ee9;
	}

	span.anticon {
		display: flex;
		justify-content: center;
		align-items: center;
	}
}

.ant-input {
	width: 130px;
}
</style>
